using HKB.Common;
using HKB.Data.Dal.S_ReviewTableAdapters;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
namespace HKB.Web
{
	public class Shop_Review
	{
		private Conn conn = null;
		private static readonly HLShop_ReviewTableAdapter Adapter = new HLShop_ReviewTableAdapter();
		private Pagination _pageHand = null;
		protected Pagination pageHand
		{
			get
			{
				Pagination pageHand;
				if (this._pageHand == null)
				{
					this._pageHand = new Pagination();
					this._pageHand.SQL_CloseTablePre = false;
					this._pageHand.SQL_Fields = "*,(Select ProductName from [HLShop_Product] Where HLShop_Product.ProductID=HLShop_Review.ProductID)as ProductName";
					this._pageHand.P_Object = Language.GetAdminMsg("Review/ReviewName");
					pageHand = this._pageHand;
				}
				else
				{
					pageHand = this._pageHand;
				}
				return pageHand;
			}
		}
		public Shop_Review(Conn _conn)
		{
			this.conn = _conn;
		}
		public Shop_Review()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetAllReviews(int indexpage, int maxperpage, string WhereStr, string OrderByStr)
		{
			return this.pageHand.GetDataTable("HLShop_Review", indexpage, maxperpage, "ReviewsID", WhereStr, OrderByStr, this.conn, null);
		}
		public DataTable GetAllReviews(int indexpage, int maxperpage, string WhereStr, string OrderByStr, params IDbDataParameter[] param)
		{
			return this.pageHand.GetDataTable("HLShop_Review", indexpage, maxperpage, "ReviewsID", WhereStr, OrderByStr, this.conn, param);
		}
		public string GetPagePanel(string linkHead)
		{
			this.pageHand.P_LinkHead = linkHead;
			return this.pageHand.ShowPagePanel();
		}
		public DataTable GetbargainorReviewCount(int UserID)
		{
			SqlParameter sqlParameter = this.conn.CreateParameter("@ReviewerID", SqlDbType.Int, UserID);
			return this.conn.GetDataTable("pr_GetbargainorReviewCount", new SqlParameter[]
			{
				sqlParameter
			});
		}
		public DataTable GetpurchaserReviewCount(int UserID)
		{
			SqlParameter sqlParameter = this.conn.CreateParameter("@ReviewerID", SqlDbType.Int, UserID);
			return this.conn.GetDataTable("pr_GetpurchaserReviewCount", new SqlParameter[]
			{
				sqlParameter
			});
		}
		public DataTable GetReviewBySideStarShopID(int Size, int Star, int UserID, int ReviewerID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				this.conn.CreateParameter("@Size", SqlDbType.Int, Size),
				this.conn.CreateParameter("@Star", SqlDbType.Int, Star),
				this.conn.CreateParameter("@UserID", SqlDbType.Int, UserID),
				this.conn.CreateParameter("@ReviewID", SqlDbType.Int, ReviewerID)
			};
			return this.conn.GetDataTable("pr_GetReviewBySideStarShopID", parameters);
		}
		public DataTable GetReviewByReviewID(int ReviewID)
		{
			DataTable result;
			if (ReviewID > 0)
			{
				result = Shop_Review.Adapter.GetReviewByReviewID(ReviewID);
			}
			else
			{
				result = null;
			}
			return result;
		}
		public void DeleteReview(int ReviewID)
		{
			Shop_Review.Adapter.DeleteReview(ReviewID);
		}
		public bool AddReviewer(int ShopID, int ProductID, int UserID, string UserName, string ReviewTitle, string ReviewContent, int ReviewStar, DateTime ReviewDate, int TransSize, int ReviewerID, string ReviewerName, int OrderID, int ReviewStatus)
		{
			int num = Shop_Review.Adapter.InsertReviewer(new int?(ShopID), new int?(ProductID), new int?(UserID), UserName, ReviewTitle, ReviewContent, new int?(ReviewStar), new DateTime?(ReviewDate), new int?(TransSize), new int?(ReviewerID), ReviewerName, new int?(OrderID), new int?(ReviewStatus));
			return num > 0;
		}
		public bool UpdateReview(int ReviewsID, int ReviewStar, string ReviewTitle, string ReviewContent)
		{
			int num = Shop_Review.Adapter.pr_UpdateReview(new int?(ReviewsID), ReviewTitle, ReviewContent, new int?(ReviewStar));
			return num > 0;
		}
		public DataTable GetAdminReview(string SearchType, string QuickSearchType, string DetailSearchType, int PageIndex, int PageSize, int Count, string SearchText, string StartDate, string EndDate)
		{
			string tblName = "HLShop_Review";
			string strGetFields = "ShopID,ProductID,UserID,ReviewsID,OrderID,UserName,ReviewTitle,ReviewContent,ReviewStar,ReviewDate,TransSize,ReviewerID,ReviewerName,ReviewStatus,(Select ProductName From HLShop_Product WHERE HLSHop_Product.ProductID=HLShop_Review.ProductID)As ProductName ";
			string fldName = "ReviewsID";
			int value = 10;
			int value2 = 1;
			int value3 = 0;
			string text = " 1=1 ";
			if (PageIndex > 0)
			{
				value2 = PageIndex;
			}
			if (PageSize > 10)
			{
				value = PageSize;
			}
			if (SearchType == "QuickSearch")
			{
				switch (QuickSearchType)
				{
				case "today":
					text += " and DateDiff(dd,ReviewDate,GetDate())=0";
					break;
				case "week":
					text += " and ReviewDate>dateadd(day,-7,GetDate())";
					break;
				case "legal":
					text += " and ReviewStatus=1";
					break;
				case "illegal":
					text += " and ReviewStatus=0";
					break;
				case "salergood":
					text += " and ReviewStar=1 AND TransSize=1";
					break;
				case "salercom":
					text += " and ReviewStar=0 AND TransSize=1";
					break;
				case "salerbad":
					text = " ReviewStar=-1 AND TransSize=1";
					break;
				case "buyergood":
					text += " and ReviewStar=1 AND TransSize=0";
					break;
				case "buyercom":
					text += " and ReviewStar=0 AND TransSize=0";
					break;
				case "buyerbad":
					text += "and ReviewStar=-1 AND TransSize=0";
					break;
				case "all":
					text += " and ReviewsID>0";
					break;
				}
			}
			else
			{
				if (SearchType == "DetailSearch")
				{
					if (DetailSearchType != null)
					{
						if (!(DetailSearchType == "reviewer"))
						{
							if (!(DetailSearchType == "review_to"))
							{
								if (!(DetailSearchType == "title"))
								{
									if (DetailSearchType == "content")
									{
										text = "ReviewContent like '%" + SearchText + "%'";
									}
								}
								else
								{
									text = "ReviewTitle like '%" + SearchText + "%'";
								}
							}
							else
							{
								text = "ReviewerName like '%" + SearchText + "%'";
							}
						}
						else
						{
							text = "UserName like '%" + SearchText + "%'";
						}
					}
					if (StartDate != "" && EndDate != "")
					{
						string text2 = text;
						text = string.Concat(new string[]
						{
							text2,
							" AND (ReviewDate>",
							StartDate,
							" AND ReviewDate<",
							EndDate,
							")"
						});
					}
				}
			}
			return Shop_Review.Adapter.GetAdminReview(tblName, strGetFields, fldName, new int?(value), new int?(value2), new int?(value3), text, new int?(Count));
		}
		public bool AdminReview(string ReviewIDArray, string Action)
		{
			bool result;
			if (Action != null)
			{
				string text;
				if (!(Action == "delete"))
				{
					if (!(Action == "illegal"))
					{
						if (!(Action == "legal"))
						{
							if (!(Action == "delete_substract"))
							{
								goto IL_62;
							}
							text = "Delete From HLShop_Review";
						}
						else
						{
							text = "Update HLShop_Review Set ReviewStatus=1";
						}
					}
					else
					{
						text = "Update HLShop_Review Set ReviewStatus=0";
					}
				}
				else
				{
					text = "Delete From HLShop_Review";
				}
				text = text + " WHERE ReviewsID in (" + ReviewIDArray + ")";
				int num = this.conn.Execute(text);
				result = (num >= 1);
				return result;
			}
			IL_62:
			result = false;
			return result;
		}
	}
}
